package com.wizz.trade.information.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wizz.trade.information.dto.page.BankInfoPageDto;
import com.wizz.trade.information.entity.Bankinfo;
import com.wizz.trade.information.mapper.BankinfoMapper;
import com.wizz.trade.information.service.BankinfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wizz.trade.util.PageUtil;
import com.wizz.trade.common.PageVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 银行信息表 服务实现类
 * </p>
 *
 * @author fyftless
 * @since 2023-04-02 04:26:06
 */
@Service
public class BankinfoServiceImpl extends ServiceImpl<BankinfoMapper, Bankinfo> implements BankinfoService {

    @Resource
    private BankinfoMapper bankinfoMapper;

    @Override
    public void addBankinfo(Bankinfo bankinfo) {
        bankinfoMapper.insert(bankinfo);
    }

    @Override
    public void updateBankinfo(Bankinfo bankinfo) {
        bankinfoMapper.updateById(bankinfo);
    }

    @Override
    public void deleteBankinfo(Integer id) {
        bankinfoMapper.deleteById(id);
    }

    @Override
    public PageVo<Bankinfo> getPage(BankInfoPageDto bankInfoPageDto) {
        LambdaQueryWrapper<Bankinfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(bankInfoPageDto.getName()),Bankinfo::getName, bankInfoPageDto.getName());
        queryWrapper.eq(!Objects.isNull(bankInfoPageDto.getCompany()), Bankinfo::getCompany, bankInfoPageDto.getCompany());
        IPage<Bankinfo> page = bankinfoMapper.selectPage(PageUtil.initPage(bankInfoPageDto), queryWrapper);
        return new PageVo<>(page);
    }

    @Override
    public List<Bankinfo> getAll() {
        return bankinfoMapper.selectList(null);
    }

}
